/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.au.uq.datamining.session;

import edu.au.uq.datamining.entity.AdditionalInfo;
import edu.au.uq.datamining.entity.BasicInfo;
import edu.au.uq.datamining.entity.Datamart;
import edu.au.uq.datamining.entity.Tpersonaid;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author oracle
 */
@Stateless
public class Manager implements ManagerRemote {
@PersistenceContext
    EntityManager em;

    public void saveData(AdditionalInfo additionalInfo, BasicInfo basicInfo) {
        em.persist(additionalInfo);
        em.persist(basicInfo);
    }



    public List<Datamart> getAllData() {
        String consultaNamedQuery = "Datamart.findAll";
        Query query = em.createNamedQuery(consultaNamedQuery);
        return (List<Datamart>) query.getResultList();

    }

    public Integer getMaxPerson() {
        Integer resultado = 0;
        String consultaFuncionRaiz = "select max(p.cpersona) from Tpersonaid p";
        Query query = em.createQuery(consultaFuncionRaiz);
        List resultados = (List) query.getResultList();
        for (int i = 0; i < resultados.size(); i++) {
            resultado = (Integer) resultados.get(i);
        }
        return resultado + 1;
    }

    public void savePerson(Tpersonaid parameter) {
        em.persist(parameter);
    }
}
